<template>
  <view class="main">
    <u-input v-model="value" height="90" class="code_input"
             :custom-style="inputStyle"
             placeholder="请输入兑换码"/>
    <view class="btn_wrp">
      <u-button type="primary" @click="exchage_code" shape="circle" :custom-style="customStyle">兑换</u-button>
    </view>
  </view>
</template>

<script>
  import {TOAST} from "../../util/util";
  import {request} from "../../util/api";

  export default {
    data() {
    	return {
    		value: '',
        customStyle: {
					background: '#1f476d',
					padding: '0 30rpx'
				},
        inputStyle: {
    			background: '#fff',
					padding: '0 30rpx'
        }
      }
    },

	  methods: {
		  exchage_code() {
			  if (!this.value) {
				  TOAST('兑换码不能为空！');
			  } else {
				  request({
					  url: '/app/exCode/use/' + this.value,
					  method: 'post'
				  }).then( res => {
				  	uni.showModal({
              title: '提示',
              content: '恭喜您，兑换成功',
              showCancel: false,
              success: function (res) {
                uni.navigateBack()
              }
            });
          })
			  }
		  }
    }
  }
</script>

<style scoped lang="scss">
  page {
		background: #F7F7F7;
	}
  .main {
    box-sizing: border-box;
    font-size: 32upx;
    height: 100%;
    background: #f7f7f7;
    .btn_wrp {
      width: 96%;
      margin: 0 auto;
      margin-top: 40upx;
    }
  }
</style>